package routers

import (
	"github.com/gin-gonic/gin"

	"shorten/internal/controller"
	"shorten/internal/middleware"
)

func NewRouter() *gin.Engine {
	r := gin.New()
	r.Use(middleware.Recover())
	r.Use(middleware.Tracing())
	control := controller.ControlIns

	r.NoRoute(control.Miss)              //404路由
	r.GET("/", control.HomePage)         //首页
	r.POST("register", control.Register) //注册
	r.POST("login", control.Login)       //登录

	logged := r.Group("", middleware.JWTAuthMiddleware())
	_shorten := logged.Group("shorten")
	{
		_shorten.POST("new", control.GenOne)       //创建新的短地址
		_shorten.GET("show/:sign", control.GetOne) //获取一个短地址
		_shorten.GET("rank", control.Rank)         //短地址排行
	}
	return r
}
